<!doctype html>
<html class="no-js">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="description" content="">
    <meta name="keywords" content="">
    <meta name="viewport"
          content="width=device-width, initial-scale=1">
    <title>轮播内容</title>

    <!-- Set render engine for 360 browser -->
    <meta name="renderer" content="webkit">

    <!-- No Baidu Siteapp-->
    <meta http-equiv="Cache-Control" content="no-siteapp"/>

    <link rel="icon" type="image/png" href="../assets/i/favicon.png">

    <!-- Add to homescreen for Chrome on Android -->
    <meta name="mobile-web-app-capable" content="yes">
    <link rel="icon" sizes="192x192" href="../assets/i/app-icon72x72@2x.png">

    <!-- Add to homescreen for Safari on iOS -->
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-title" content="Amaze UI"/>
    <link rel="apple-touch-icon-precomposed" href="../assets/i/app-icon72x72@2x.png">

    <!-- Tile icon for Win8 (144x144 + tile color) -->
    <meta name="msapplication-TileImage" content="assets/i/app-icon72x72@2x.png">
    <meta name="msapplication-TileColor" content="#0e90d2">

    <link rel="stylesheet" href="../assets/css/amazeui.min.css">
    <link rel="stylesheet" href="../assets/css/app.css">

    <!--在这里编写你的代码-->

    <!--[if (gte IE 9)|!(IE)]><!-->
    <script src="../js/jquery2.js"></script>
    <!--<![endif]-->
    <!--[if lte IE 8 ]>
    <script src="http://libs.baidu.com/jquery/1.11.3/jquery.min.js"></script>
    <script src="http://cdn.staticfile.org/modernizr/2.8.3/modernizr.js"></script>
    <script src="../assets/js/amazeui.ie8polyfill.min.js"></script>
    <![endif]-->
    <script src="../assets/js/amazeui.min.js"></script>
    <script src="../js/vue.js"></script>
    <!--    弹框-->
    <link rel="stylesheet" type="text/css" href="../swal/sweetalert2.min.css">
    <script src="../swal/sweetalert2.min.js"></script>
    <!-- for IE support -->
    <script src="../swal/promise.min.js"></script>
    <!--    <script src="../js/options.js"></script>-->
</head>

<style>
    body {
        -webkit-font-smoothing: antialiased;
        -moz-osx-font-smoothing: grayscale;
    }

    /*.lhl-box-3 li{*/
    /*    padding: 10px;*/
    /*}*/
    .lhl-card-h1 {
        margin: 10px;
        font-size: 30px;
        color: #000;
    }

    #lhl-right {
        margin: 0px;
        padding: 30px;
        background: #ecf0f1;
        min-height: 1200px;
    }

    #lhl-head {
        margin: 0px;
    }

    #lhl-card {
        padding: 0px 80px 0px 80px;
    }

    #lhl-card li {
        /*padding: 0px 80px 0px 80px;*/
    }

    .lhl-echar {
        padding: 0px 80px 0px 80px;
    }

    .lhl-echar-card {
    }

    .lhl-nomargin {
        margin: 0px;
    }

    .lhl-list {
        padding-top: 10px;
    }

    .lhl-list h3 {
        margin: 0px;
        /*font-weight: bold;*/
    }

    .am-nav-header {
        border-left: 3px solid #3bb4f2;

    }

    .am-nav > li + .am-nav-header {
        margin-top: 0px;
    }
</style>

<body>
<div id="app">
    <!-- 头部区域开始 -->
    <header class="am-topbar am-topbar-inverse" id="lhl-head">
        <h1 class="am-topbar-brand">
            <a href="#">Tweet 后台管理</a>
        </h1>

        <button class="am-topbar-btn am-topbar-toggle am-btn am-btn-sm am-btn-success am-show-sm-only"
                data-am-collapse="{target: '#doc-topbar-collapse'}"><span class="am-sr-only">导航切换</span> <span
                class="am-icon-bars"></span></button>

        <div class="am-collapse am-topbar-collapse" id="doc-topbar-collapse">

            <div class="am-topbar-right">
                <div class="am-dropdown" data-am-dropdown="{boundary: '.am-topbar'}">
                    <button class="am-btn am-btn-secondary am-topbar-btn am-btn-sm am-dropdown-toggle"
                            data-am-dropdown-toggle>用户信息 <span class="am-icon-caret-down"></span></button>
                    <ul class="am-dropdown-content">
                        <li><a href="#">用户名:{{UserName}}</a></li>
                        <li><a href="#">修改密码</a></li>
                    </ul>
                </div>
            </div>

            <div class="am-topbar-right">
                <button class="am-btn am-btn-primary am-topbar-btn am-btn-sm" @click="userLogin">管理员登录</button>
            </div>
        </div>
    </header>
    <!-- 头部区域结束 -->
    <!-- 数据化信息开始-->
    <div class="am-g lhl-min-height">
        <div class="am-u-lg-2">
            <ul class="am-nav lhl-list">
                <li><a href="./data.html">首页</a></li>
                <li class="am-nav-divider"></li>
                <li><a href="./data.html">数据展示</a></li>
                <li><a href="./user.html">用户管理</a></li>
                <li><a href="./tweet.html">推文管理</a></li>
                <li><a href="./tweet.html">账户管理</a></li>
                <li><a href="./editor.html">文章管理</a></li>
                <li class="am-nav-header">推广管理</li>
            </ul>
        </div>
        <div class="am-u-lg-10" id="lhl-right">
            <h1>推广管理</h1>
            <div class="am-u-lg-12">
                <table class="am-table am-table-bordered am-table-radius" style="background-color:#fff; padding-top: 10px;">
                    <tr>
                        <td>
                            图文编辑
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <ul class="am-avg-lg-4">
                                <li>
                                    <img v-bind:src="headList[0].img" width="100%">
                                    <div class="am-slider-desc"><strong>标题:</strong> {{headList[0].text}}</div>
                                    <button class="am-btn am-btn-block am-btn-warning" @click="setImage(0)">编辑首屏</button>
                                </li>
                                <li>
                                    <img v-bind:src="headList[1].img" width="100%">
                                    <div class="am-slider-desc"><strong>标题:</strong> {{headList[1].text}}</div>
                                    <button class="am-btn am-btn-block am-btn-warning" @click="setImage(1)">编辑2屏</button>
                                </li>
                                <li>
                                    <img v-bind:src="headList[2].img" width="100%">
                                    <div class="am-slider-desc"><strong>标题:</strong> {{headList[2].text}}</div>
                                    <button class="am-btn am-btn-block am-btn-warning" @click="setImage(2)">编辑3屏</button>
                                </li>
                                <li>
                                    <img v-bind:src="headList[3].img" width="100%">
                                    <div class="am-slider-desc"><strong>标题:</strong> {{headList[3].text}}</div>
                                    <button class="am-btn am-btn-block am-btn-warning" @click="setImage(3)">编辑4屏</button>
                                </li>
                            </ul>
                        </td>
                    </tr>
                </table>
            </div>

        </div>

    </div>
    <!-- 数据化信息结束-->
</div>


<script type="text/javascript">
    var app = new Vue({
        el: "#app",
        data: {
            UserPassword: '',
            UserName: '',
            headList:[
                {
                    img:'http://s.amazeui.org/media/i/demos/bing-1.jpg',
                    text:'远方 有一个地方 那里种有我们的梦想'
                },
                {
                    img:'http://s.amazeui.org/media/i/demos/bing-2.jpg',
                    text:'远方 有一个地方 那里种有我们的梦想'
                },
                {
                    img:'http://s.amazeui.org/media/i/demos/bing-3.jpg',
                    text:'远方 有一个地方 那里种有我们的梦想'
                },
                {
                    img:'http://s.amazeui.org/media/i/demos/bing-4.jpg',
                    text:'远方 有一个地方 那里种有我们的梦想'
                }
            ],
        },
        methods: {
            inputPwd: function () {
                swal({
                    title: '输入密码',
                    input: 'password',
                    inputAttributes: {
                        'maxlength': 30,
                        'autocapitalize': 'off',
                        'autocorrect': 'off'
                    }
                }).then(function (result) {
                    app.UserPassword = result;
                    $.post('../manager', {
                        type: 'login',
                        username: app.UserName,
                        password: app.UserPassword
                    }, function (response) {
                        if (response == "success") {
                            swal(
                                '您好！' + app.UserName,
                                '欢迎登录后台管理，请为所欲为吧!',
                                'success'
                            );
                        } else {
                            swal(
                                '登陆失败！',
                                '抱歉您登录不成功，没办法为所欲为!',
                                'error'
                            )
                        }
                    });
                })
            },
            userLogin: function () {
                //登录
                swal({
                    title: '输入登录账号',
                    input: 'text',
                    showCancelButton: true,
                    inputValidator: function (value) {
                        return new Promise(function (resolve, reject) {
                            if (value) {
                                resolve();
                            } else {
                                reject('请填写账号');
                            }
                        });
                    }
                }).then(function (result) {
                    // 输入用户完成
                    app.UserName = result;
                    app.inputPwd();
                })
            },
            setImage:function (id) {
                //设置图片
                swal({
                    title: '选择图片',
                    input: 'file',
                    inputAttributes: {
                        accept: 'image/*'
                    }
                }).then(function(file) {
                    if (file) {
                        var reader = new FileReader;
                        reader.onload = function(e) {
                            // e.target.result
                            // swal({
                            //     imageUrl:e.target.result
                            // });
                            var data=e.target.result;
                            var image=new Image();
                            image.onload=function () {
                                //判断图片尺寸
                                var height=image.height;
                                var width=image.width;
                                if (height!=768 && width!=1366){
                                    swal({
                                        type: "error",
                                        title:"图片尺寸错误",
                                        text:"图片尺寸不符合要求,要求1366*768,输入图片"+width+"*"+height
                                    })
                                }else{
                                    Vue.set(app.headList[id],'img',data);
                                    app.setTitle(id); //调用设置标题内容
                                }
                            };
                            image.src=data;

                        };
                        reader.readAsDataURL(file);
                    }
                })
            },
            setTitle:function (id) {
                //设置标题
                swal({
                    title: '输入设置的标题',
                    input: 'text',
                    showCancelButton: true,
                    inputValidator: function(value) {
                        return new Promise(function(resolve, reject) {
                            if (value) {
                                resolve();
                            } else {
                                reject('你需要写入内容');
                            }
                        });
                    }
                }).then(function(result) {
                    if (result) {
                        // swal({
                        //     type: 'success',
                        //     html: 'You entered: ' + result
                        // });
                        console.log(id);
                        Vue.set(app.headList[id],'text',result);
                        app.sumbitChange(id);
                        // swal({
                        //     type:'success',
                        //     title:'设置成功',
                        // });

                    }
                })
            },
            sumbitChange:function (id) {
                swal({
                    title: '是否提交',
                    text: "当前轮播图已设置完毕，是否提交更改",
                    type: 'question',
                    showCancelButton: true,
                    confirmButtonColor: '#3085d6',
                    cancelButtonColor: '#d33',
                    confirmButtonText: '提交',
                    cancelButtonText: '取消',
                    confirmButtonClass: 'am-btn am-btn-primary',
                    cancelButtonClass: 'am-btn am-btn-danger',
                    buttonsStyling: false
                }).then(function(isConfirm) {
                    if (isConfirm === true) {
                        //此处进行请求
                        $.post('../manager', {
                            type: 'head.set',
                            id:id,
                            title:app.headList[id].text,
                            image:app.headList[id].img.split(",")[1]
                        }, function (result) {
                            result=JSON.parse(result);
                            if (result.result){
                                swal(
                                    '成功',
                                    '修改成功',
                                    'success'
                                );
                            }else{
                                swal(
                                    '错误',
                                    '修改出现错误',
                                    'error'
                                );
                            }
                        });


                    } else if (isConfirm === false) {
                        swal(
                            '取消',
                            '取消提交',
                            'warning'
                        );
                    } else {
                        // Esc, close button or outside click
                        // isConfirm is undefined
                    }
                })
            }
        },
        created:function () {
            $.post("../queryhead",{},function (result) {
                if (result!=""){
                    result=JSON.parse(result);
                    // Vue.set(app,'headList',result.result);
                    for (var i=0;i<result.result.length;i++){
                        Vue.set(app.headList[i],'text',result.result[i].text);
                        Vue.set(app.headList[i],'img',"../image?src="+result.result[i].img);
                    }
                }
            });
        }
    });
</script>
<!--<script src="../js/options.js"></script>-->
<!--<script src="../js/manager_js.js"></script>-->
</body>
</html>